package com.bnd.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.file.Path;
import java.nio.file.Paths;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    // 修改路径指向 ai-releplay-hub-backend 子目录下的 uploads
    private static final String UPLOAD_DIR = Paths.get(System.getProperty("user.dir"), "ai-roleplay-hub-backend", "uploads").toString();

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 映射 /static/** 到 classpath:/static/
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");

        // 映射 /uploads/** 到 file:{project-root}/ai-releplay-hub-backend/uploads/
        registry.addResourceHandler("/uploads/**")
                .addResourceLocations("file:" + UPLOAD_DIR + "/");
    }
}
